<?php
/**
 * Created by viva.
 * User: xj
 * Tel:  13675170078
 * Date: 2015/6/8
 * Time: 17:22
 */
namespace Admin\Controller;

use Home\Controller\StrategyController;

class AdController extends CommonController
{

    public function adList()
    {
        $AdModel = M('NavAd');
        $this->assign('ad', $AdModel->select());
        $this->display();
    }

    public function edit()
    {
        $id = I('id');
        if ($id) {
            $NavAd = M('NavAd');
            $result = $NavAd->where(array('id' => $id))->find();
            $this->assign('ad', $result);
        }
        $this->display();
    }

    public function add()
    {
        $this->display();
    }

    public function update()
    {
        $NavAdModel = M('NavAd');
        $NavAdModel->create();
        if ($_FILES['img']['size'] != 0) {
            $file = new FileController();
            $img_info = $file->upload('ad_img');
            $NavAdModel->img = $img_info['img']['savepath'] . $img_info['img']['savename'];
        }
        $NavAdModel->start_time = strtotime(I('start_time'));
        $NavAdModel->end_time = strtotime(I('end_time'));
        if (!I('id'))
            $NavAdModel->add();
        else
            $NavAdModel->save();

        $this->success('编辑成功');
    }

    public function remove()
    {
        $id=I('id');

        if($id)
        {
            $NavAd=M('NavAd');
            $NavAd->delete($id);
        }
        $this->ajaxReturn(1);
    }

    public function test()
    {
        $this->display();
    }
}